﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://wubiyu.cnblogs.com">
<head>
      <title></title>
      <link href="../../Theme/DomExtGray/gray.min.css" rel="Stylesheet" type="text/css" />
      <link href="PageModel.css" rel="Stylesheet" type="text/css" />
      <script type="text/javascript" src="../../domExt.js"></script>
</head>
<body>
      <div  class="fun_title">
            _h.each(o, fn(key,o[key]){},[args]);
      </div>
      <div class="fun_content">
            描述：通用例遍方法，可用于例遍对象和数组。<br />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 此方法可用于例遍任何对象。</div>
      <div class="fun_title2">
            参数:
      </div>
      <div class="fun_content2" >
           o：对象和数组<br />
            fn：回调函数<br />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            key：对象的成员或数组的索引。<br />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            o[key]：对应变量或内容。<br />
            args:传入参数<br />
            <strong>Retrun:</strong><br />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            如果需要退出 each 循环可使回调函数返回 "break"，如果需要退出本次可返回"continue"<br /><br />
      </div>
      <div class="fun_title2">
            示例:
      </div>

      <div class="code">
            &lt;script type=&quot;text/javascript&quot;&gt;<br />
            &nbsp;&nbsp;&nbsp; _h.each([1, 2, 3], function (i, v) {
            <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert(&quot;key=&quot; + i + &quot; o[key]=&quot; + v);
            <br />
&nbsp;&nbsp;&nbsp; });
            <br />
&nbsp;&nbsp;&nbsp; _h.each({ id: &quot;1&quot;, name: &quot;wubiyu&quot; }, function (i,v) {
            <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert(&quot;key=&quot; + i + &quot; o[key]=&quot; + v);
            <br />
&nbsp;&nbsp;&nbsp; });<br />
            &lt;/script&gt;</div>
      <br />
      <div id="msg"></div>
      <h:btn onclick="run_click();">执行脚本</h:btn> <br /><br />
       <div  class="fun_title">
           h.eachAsy = function(arrayObj,fn(index,item),callback(),setObj)
      </div>
      <div class="fun_content">
            描述：通用异步遍例方法，可用于例遍对象和数组。<br />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 此方法可用于例遍任何对象。</div>
      <div class="fun_title2">
            参数:
      </div>
      <div class="fun_content2" >
            arrayObj：数组<br />
            fn：回调函数<br />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            index：下标索引。<br />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            item: 对象<br />
            callback()：完成函数。<br />
            setObj: 异步调用时间设置。<br />
                 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                 runTime: 连继执行时间，默认 100ms<br />
                 waittingTime:等待时间，默认 25ms<br />
            <strong>Retrun: </strong>void<br />

          
      </div>
      <div class="fun_title2">
            示例:
      </div>
       <div class="code">
       
            &lt;script type=&quot;text/javascript&quot;&gt;<br />
&nbsp;&nbsp;&nbsp; var dataArray = new Array();
           <br />
&nbsp;&nbsp;&nbsp; for (var i = 0; i &lt; 1000; i++) { dataArray.push(i); }<br />
&nbsp;&nbsp;&nbsp; _h.eachAsy(dataArray, function (i) { _g(&quot;#msg2&quot;).html(_g(&quot;#msg2&quot;).html() 
           + &quot; &quot; + i); }, function () { alert(&quot;执行完成&quot;); });<br />
            &lt;/script&gt;</div><br />
       <div id="msg2">msg2</div>
      <h:btn onclick="run_click2();">执行脚本</h:btn>
      <script type="text/javascript">
          var dataArray = new Array();
          for (var i = 0; i < 5000; i++) {
              dataArray.push(i);
          }
          function run_click() {
                  _h.each(dataArray, function (i, v) {
                        _g("#msg").html(_g("#msg").html() + "key=" + i + " o[key]=" + v + " ");
                  });
           };
                
        function run_click2() {
            var html = "";
            _h.eachAsy(dataArray, function (i) {
                _g("#msg2").html(_g("#msg2").html() + " " + i);
            }, function () {
                alert("执行完成");
            });
        };
              
      </script>
</body>
</html>
